#include <stdio.h>
#include <stdlib.h>

struct Stu
{
	int num;
	char name[20];
	double grade;
};

int main()
{
	struct Stu student;
	FILE *input,*output;
	input = freopen("student.txt","rb",stdin);
	if(input==NULL)
	{
		printf("No student list!\n"); 
	}//?????,???????????????
	while(scanf("%i%s%lf",&student.num,student.name,&student.grade) != EOF)
	{
		printf("num:%03i name:%s grade:%.2lf\n",student.num,student.name,student.grade);
	}
	fclose(input);
	int tmp = 1;
	freopen("CON", "rb", stdin);
	while(1)
	{
		printf("Do you want to add new student information?\nPress 1 to add, press 0 to quit.\n");
		scanf("%i",&tmp);
		if(tmp == 0)
		{
			break;
		}
		printf("Now you can input the num, name and grade.\n");
		scanf("%i",&student.num);
		scanf("%s",student.name);
		scanf("%lf",&student.grade);
		printf("Now finished.\n");
		output = freopen("student.txt","ab",stdout);
		{
			printf("%i %s %.2lf\n",student.num,student.name,student.grade);
		}
		fclose(output);
		freopen("CON", "wb", stdout);
	}
	return 0;
} 
